package Exer01;

import lombok.Getter;

@Getter()
public class Account {
    private double balance = 3000;

    private static final Account account = new Account();

    private Account() {

    }

    public static Account getInstance() {
        return account;
    }

    public synchronized void deposit(double money) {
        if (balance >= money) {
            balance -= money;
            System.out.println(Thread.currentThread().getName() + "--成功取出" + money + "元。剩余" + balance + "元。");
        } else
            System.out.println("余额不足。剩余" + balance + "元。");
    }

    public void save(double money) {
        balance += money;
    }
}
